package com.kfm.pm.stream;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo02 {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        Collections.addAll(list, "phr", "phr", "pyy", "pyc", "zk", "pl");
        // 找到姓彭 三个字 不重复的放到新的集合
        Stream<String> stream = list.stream();
        List<String> collect = stream.filter(s -> s.startsWith("p") && s.length() == 3).distinct().collect(Collectors.toList());
        System.out.println(collect);
        Stream<String> stream1 = list.stream();
        stream1.sorted().forEach(s -> System.out.println(s));
        List<HairStyle> hairStyleList = new ArrayList<>();
        Collections.addAll(hairStyleList, new HairStyle("中分", 30, "灰色"),
                new HairStyle("平头", 15, "黑色"),
                new HairStyle("大波浪", 200, "黄色"));
        List<HairStyle> collect1 = hairStyleList.stream().filter(h -> h.getMoney() >= 30).collect(Collectors.toList());
        System.out.println(collect1);
        hairStyleList.stream().sorted().forEach(h -> System.out.println(h));
        System.out.println("=======");
        hairStyleList.stream().peek(new Consumer<HairStyle>() {
            @Override
            public void accept(HairStyle hairStyle) {
                System.out.println("filter之前:" + hairStyle.getMoney());
            }
        }).filter(h -> h.getMoney() >= 30).peek(s -> System.out.println("之后：" + s.getName())).forEach(h -> System.out.println(h));
        System.out.println("====");
        Object[] collect2 = hairStyleList.stream().map(new Function<HairStyle, Object>() {
            @Override
            public Object apply(HairStyle hairStyle) {
//                System.out.println(hairStyle);
                return new HairStyle("学生头", 20, "黑色");
            }
        }).toArray();
        System.out.println(Arrays.toString(collect2));
//        HashMap hashMap = new HashMap();
//        hashMap.c
    }
}
